﻿using System;
using System.Configuration;
using UtfprLibrary.Exceptions;

namespace UtfprLibrary.Configurations {
    /// <summary>
    /// Configuration of common UtfprLibrary settings
    /// </summary>
    public static class UtfprSettings {
        /// <summary>
        /// Default configuration section, named "utfpr"
        /// </summary>
        private static UtfprSection settings =
            ConfigurationManager.GetSection(Properties.Resources.Configurations_Const_Section) as UtfprSection;

        /// <summary>
        /// Default contructor that checks for a configuration section named "utfpr", throwing an exception if not found
        /// </summary>
        /// <exception cref="UtfprLibrary.Exceptions.UtfprConfigurationsException">Thrown when an exception occurs.</exception>
        static UtfprSettings() {
            if (settings == null) {
                throw new UtfprConfigurationsException("Section '" + Properties.Resources.Configurations_Const_Section + "' not found.");
            }
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <exception cref="UtfprLibrary.Exceptions.UtfprConfigurationsException">Thrown when an exception occurs.</exception>
        public static string SecurityBranch {
            get {
                try {
                    return settings.Security.Branch;
                } catch (Exception ex) {
                    throw new UtfprConfigurationsException("Branch not found.", ex);
                }
            }
        }
    }
}
